#include <iostream>
#include <unordered_map>
#include <cmath>
using namespace std;
bool is_prime(int num)
{
    if (num < 2)
    {
        return false;
    }
    for (int i = 2; i <= sqrt(num); i++)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
    return true;
}

int closest_prime(int num)
{
    if (is_prime(num))
    {
        return num;
    }

    int lower = num - 1;
    int upper = num + 1;

    while (true)
        {
        if (is_prime(lower))
        {
            return lower;
        }
        else if (is_prime(upper))
        {
            return upper;
        }
        else
        {
            lower--;
            upper++;
        }
    }
}

int word_to_number(const string& word)
{
    unordered_map<string, int> numbers = {
        {"zero", 0}, {"one", 1}, {"two", 2}, {"three", 3}, {"four", 4},
        {"five", 5}, {"six", 6}, {"seven", 7}, {"eight", 8}, {"nine", 9}
    };
    return numbers[word];
}

int main() {
    string word1, word2, word3;
    cin >> word1 >> word2 >> word3;

    try {
        int number = word_to_number(word1) * 100 + word_to_number(word2) * 10 + word_to_number(word3);
        if (number >= 100 && number <= 999) {
            cout << closest_prime(number) << endl;
        } else {
            cout << "Wrong input" << endl;
        }
    } catch (...) {
        cout << "Wrong input" << endl;
    }

    return 0;
}
